package com.fyyg.common.execl;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;
import com.fyyg.common.util.date.DateUtil;


/**
 * @Description: TODO  excel 表头定义   表头键定义      用于查询结果返回Map类型
 * @author xsg 
 * @date 2016年6月4日 下午1:41:06
 */
public class ExportHead {
	
	private ExportHead(){}
	
	
	/**
	 * @author xsg
	 * @date: 2016年6月25日
	 * @Description: TODO 所有的订单
	 */
	public final static class AllRecordOrders{
		
		public static final String[]  head = {"订单编号","商品编号","商品名称","商品组次",
											  "商品价格","购买人次","福豆","现金","红包","账户类型","用户标识",
											  "推荐人","注册手机","购买时间","状态"};
		
		public static final String[] key = {"record_no","product_code","product_title","group_no",
											"product_price","buy_number","money","discount_money","111", "u_type","auto_user",
											"inviter","user_name","buy_time","bonus_status"};
		
		public static Map<Long,String> inviter = null;
	}
	
	/**
	 * @author xsg
	 * @date: 2016年6月25日
	 * @Description: TODO  待发货订单
	 */
	public final static class BackOrders{
		public static final String[]  REAL_HEAD = {"订单编号","商品编号","商品名称","商品组次",
													"商品价格","购买人次","福豆","现金","红包",
													"账户类型","用户标识","注册手机","购买时间","揭晓时间","订单状态","确认地址时间"};
		
		public static final String[]  REAL_KEY = {"record_no","product_code","product_title","group_no",
												  "product_price","buy_number","money","discount_money","111", 
												  "u_type","auto_user","user_name","buy_time","q_opentime","confirm_status","add_time"};
		
		public static final String[]  VITUAL_HEAD = {"订单编号","商品编号","商品名称","商品组次",
													 "商品价格","购买人次","福豆","现金","红包",
													 "账户类型","用户标识","注册手机","充值手机","购买时间","揭晓时间","订单状态","确认地址时间"};
		public static final String[]  VITUAL_KEY = {"record_no","product_code","product_title","group_no",
			  										"product_price","buy_number","money","discount_money"," ", 
			  									    "u_type","auto_user","user_name","phone_recharge" ,"buy_time","q_opentime","confirm_status","add_time"};
	}
	
	
	
	/**
	 * @author xsg
	 * @date: 2016年6月25日
	 * @Description: TODO 待确认收货订单
	 */
	public final static class ConfirmOrders{
		public static final String[] HEAD = {"订单编号","商品编号","商品名称","商品组次",
											 "注册手机","用户ID","账户类型","收货人姓名","收货人电话","收货地址",
											 "渠道","渠道订单号","发货时间","物流公司","物流单号","物流状态"};
		public static final String[] KEY = {"record_no","product_code","product_title","group_no",
											"user_name","uid","u_type","receive_name","receive_phone","receive_address",
											"channel","channel_no","send_time","deliver_provider","courier_number","reamrk"};
	}
	
	
	/**
	 * @author xsg
	 * @date: 2016年6月25日
	 * @Description: TODO 已完成订单
	 */
	public final static class FinishOrders{
		public static final String[] ABEND_REAL_HEAD = {"订单编号","商品编号","商品名称","商品组次",
														"商品价格","注册手机","用户ID","用户属性",
														"购买时间","揭晓时间","物流公司","物流单号",
														"终止人","终止原因","完成时间"};
		
		public static final String[] ABEND_VITUAL_HEAD = {"订单编号","商品编号","商品名称","商品组次",
														  "商品价格","注册手机","用户ID","用户属性",
														  "购买时间","揭晓时间","充值手机","卡密UID",
														  "终止人","终止原因","完成时间"};
		
		public static final String[] REAL_HEAD = {"订单编号","商品编号","商品名称","商品组次",
												  "商品价格","注册手机","用户ID","用户属性",
												  "购买时间","揭晓时间","物流公司","物流单号","完成时间"};
		
		public static final String[] VITUAL_HEAD = {"订单编号","商品编号","商品名称","商品组次",
													"商品价格","注册手机","用户ID","用户属性",
													"购买时间","揭晓时间","充值手机","卡密UID","完成时间"};
		
		public static final String[] ABEND_REAL_KEY = {"record_no","product_code","product_title","group_no",
													   "product_price","user_name","uid","u_type",
													   "buy_time","q_opentime","deliver_provider","courier_number",
													    "o_user_name","mark","send_time"};
		
		public static final String[] ABEND_VITUAL_KEY = {"record_no","product_code","product_title","group_no",
			   											 "product_price","user_name","uid","u_type",
													     "buy_time","q_opentime","phone_recharge","card_number",
													     "o_user_name","mark","send_time"};
		
		public static final String[] REAL_KEY = {"record_no","product_code","product_title","group_no",
											     "product_price","user_name","uid","u_type",
											     "buy_time","q_opentime","deliver_provider","courier_number","send_time"};
		
		
		public static final String[] VITUAL_KEY = {"record_no","product_code","product_title","group_no",
												   "product_price","user_name","uid","u_type",
											       "buy_time","q_opentime","phone_recharge","card_number","send_time"};
		
		
	}
	
	
	/**
	 * @author xsg
	 * @date: 2016年6月25日
	 * @Description: TODO 问题订单
	 */
	public final static class QuestionOrders{
		public static final String[] REAL_HEAD = {"订单编号","商品编号","商品名称","商品组次",
												 "注册手机","用户ID","收货人姓名","收货人电话","收货地址",
												 "渠道","渠道订单号","发货时间","物流公司","物流单号","物流状态",
												 "上级处理人","问题原因"};
		
		public static final String[] VITUAL_HEAD = {"订单编号","商品编号","商品名称","商品组次",
													"揭晓时间","注册手机","用户ID","卡密UID","充值手机",
													"上级处理人","问题原因"};
		
		
		
		public static final String[] REAL_KEY = {"record_no","product_code","product_title","group_no",
												 "user_name","uid","u_type","receive_name","receive_phone","receive_address",
												 "channel","channel_no","send_time","deliver_provider","courier_number","reamrk",
												 "o_user_name","mark"};
		
		public static final String[] VITUAL_KEY = {"record_no","product_code","product_title","group_no",
												   "q_opentime","user_name","uid","card_number","phone_recharge",
												   "o_user_name","mark"};
	}
	
	/**
	 * @author xsg
	 * @date: 2016年6月25日
	 * @Description: TODO 卡密统计
	 */
	public final static class JDEOrders{
		
		public static final String[] HEAD = {"订单编号","商品编号","商品名称","商品组次",
											 "商品价格","卡密UID","面值","卡密",
											 "录入时间","购买人次","购买金额","购买时间",
											 "注册手机","账户类型","用户标识","充值手机",
											 "揭晓时间","发货时间"};
		
		public static final String[] KEY = {"record_no","product_code","product_title","group_no",
											"product_price","card_number","v_money","v_password",
											"jde_add_time","buy_number","money","buy_time",
											"user_name","u_type","auto_user","phone_recharge",
											"q_opentime","success_time"};
	}
	
	
	public final static class ConvertExportValue{
		
		/**
		 * @author xsg
		 * @date: 2016年6月25日
		 * @Description: TODO 值转换
		 * @param key
		 * @param value
		 * @return
		 */
		public static String convert(String key ,String value){
			 if(StringUtils.isBlank(value)){
				return ""; 
			 }
			switch(key){
				case "u_type":
					Integer j = Integer.parseInt(value);
					if(j == 0){
						value = "普通用户";
					}
					if(j == 1){
						value = "A类VIP账户";
					}
					if(j == 2){
						value = "A类子账户";
					}
					if(j == 3){
						value = "B类子账户";
					}
					if(j == 4){
						value = "B类VIP账户";
					}
					break;
				case "auto_user":
					Integer i = Integer.parseInt(value);
					if(i == 0){
						value = "无";
					}
					if(i == 1){
						value = "A";
					}
					if(i == 2){
						value = "B";
					}
					if(i == 3){
						value = "C";
					}
					if(i == 4){
						value = "D";
					}
					if(i == 9){
						value = "未标识";
					}
					break;	
				case "buy_time":
					value = DateUtil.stringDateFormat(value,"yyyy-MM-dd HH:mm:ss");
					break;
				case "q_opentime":
					value = DateUtil.stringDateFormat(value,"yyyy-MM-dd HH:mm:ss");
					break;
				case "add_time":
					 value = DateUtil.stringDateFormat(value,"yyyy-MM-dd HH:mm:ss");
					 break;	
				case "send_time":
					value = DateUtil.stringDateFormat(value,"yyyy-MM-dd HH:mm:ss");
					break;
				case "bonus_status":
					Integer k = Integer.parseInt(value);
					if(k == 0){
						value = "支持";
					}
					if(k == 1){
						value = "宝主";
					}
					break;
				case "confirm_status":
					Integer v = Integer.parseInt(value);
					if(v == 0){
						value = "未确认收货地址";
					}
					if(v == 1){
						value = "已确认收货地址";
					}
				    break;
				case "reamrk":
					JSONObject json = JSONObject.parseObject(value);
					String status = json.getString("status"); // 监控状态
					if("shutdown".equals(status)){ // 快递已经签收
						value = "已签收";
					}
					else{
						String lastResult = json.getString("lastResult"); // 最新查询结果
				    	JSONObject lastResultJson =JSONObject.parseObject(lastResult);
				    	String state = lastResultJson.getString("state"); // 快递单当前签收状态 包括0在途中、1已揽收、2疑难、3已签收、4退签、5同城派送中、6退回、7转单等7个状态
						value = getLogisticMessage(state);
					}
			    	break;
				case "inviter": // 推荐人
					Long l = Long.valueOf(value);
					if(AllRecordOrders.inviter != null){
						value = AllRecordOrders.inviter.get(l) == null ?" " :AllRecordOrders.inviter.get(l);
					}
					break;
			}
			return value;
		}
		
		
		public static String  getLogisticMessage(String state){
			String message = null;
			switch(state){
				case "0":
					message = "在途中";
					break;
				case "1":
					message = "已揽收";
					break;
				case "2":
					message = "疑难";
					break;
				case "3":
					message = "已签收";
					break;
				case "4":
					message = "退签";
					break;
				case "5":
					message = "同城派送中";
					break;
				case "6":
					message = "退回";
					break;
				case "7":
					message = "转单";
					break;
			}
			return message;
		}
	}
	
}
